package com.gwcloud.leetcode.offers;

import com.gwcloud.leetcode.common.datastructure.TreeNode;

/** 
* @ClassName   : Leetcode0680 
* @author      : ganwei 
* @date        : 2020年6月12日 
* @Description : 面试题68 - II. 二叉树的最近公共祖先 
*/
public class Leetcode0680 {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if(root == null || root == p || root == q) {
        	return root;
        }
        TreeNode left = lowestCommonAncestor(root.left, p, q);
        TreeNode right = lowestCommonAncestor(root.right, p, q);
        
        if(left == null) {
        	return right;
        }
        if(right == null) {
        	return left;
        }
        return root;
    }
    /**
     * -主函数
     */
    public static void main(String[] args) {
    	
    }
}
